home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dde2 / ddeserve.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-05-16  |  7.6 KB  |  242 lines

  1. VERSION 2.00
  2. Begin Form DDESERVER 
  3.    Caption         =   "DDE Server"
  4.    ClientHeight    =   3660
  5.    ClientLeft      =   1815
  6.    ClientTop       =   1680
  7.    ClientWidth     =   4770
  8.    Height          =   4350
  9.    Icon            =   DDESERVE.FRX:0000
  10.    Left            =   1755
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "DdeServe"
  13.    ScaleHeight     =   3660
  14.    ScaleWidth      =   4770
  15.    Top             =   1050
  16.    Width           =   4890
  17.    Begin TextBox Text2 
  18.       Height          =   2175
  19.       Left            =   1320
  20.       MultiLine       =   -1  'True
  21.       TabIndex        =   2
  22.       Top             =   960
  23.       Width           =   3015
  24.    End
  25.    Begin TextBox Text1 
  26.       Height          =   375
  27.       Left            =   1320
  28.       TabIndex        =   0
  29.       Top             =   360
  30.       Width           =   3015
  31.    End
  32.    Begin Label lblStatus 
  33.       Height          =   255
  34.       Left            =   0
  35.       TabIndex        =   4
  36.       Top             =   3360
  37.       Width           =   4695
  38.    End
  39.    Begin Label Label2 
  40.       BackStyle       =   0  'Transparent
  41.       Caption         =   "Text 2:"
  42.       Height          =   255
  43.       Left            =   240
  44.       TabIndex        =   3
  45.       Top             =   960
  46.       Width           =   975
  47.    End
  48.    Begin Label Label1 
  49.       BackStyle       =   0  'Transparent
  50.       Caption         =   "Text 1:"
  51.       Height          =   255
  52.       Left            =   240
  53.       TabIndex        =   1
  54.       Top             =   480
  55.       Width           =   1095
  56.    End
  57.    Begin Menu mnuOptionsPopup 
  58.       Caption         =   "&Options"
  59.       Begin Menu mnuOption 
  60.          Caption         =   "&Always on Top"
  61.          Index           =   0
  62.       End
  63.    End
  64. Option Explicit
  65. Const IDM_TOPMOST = 0
  66. ' NUMEXECUTECMDS is the number of execution commands MINUS 1.
  67. Const NUMEXECUTECMDS = 1
  68. Const EC_DISPLAYABOUT = 0
  69. Const EC_SHELLAPP = 1
  70. Dim ExecuteCmd(NUMEXECUTECMDS) As String
  71. Function Cmd_ShellApp (Params As String)
  72.  Dim rtn As Integer
  73.  Dim sRtn As String
  74.  Dim appname As String
  75.  Dim state As Integer
  76.    ' Shell the application defined by Params
  77.    ' First, extract the application name
  78.    If DoExtractParam(Params, appname) Then
  79.       ' Next extract the show state, if specified
  80.       state = 1
  81.       If DoExtractParam(Params, sRtn) Then
  82.          state = Val(sRtn)
  83.       End If
  84.       ' Now, shell the application
  85.       Cmd_ShellApp = Shell(appname, state)
  86.       Exit Function
  87.    Else
  88.       ' No app name found
  89.       Cmd_ShellApp = False
  90.       Exit Function
  91.    End If
  92. End Function
  93. Sub DisplayStatus (sParam As String)
  94.    lblStatus.Caption = sParam
  95. End Sub
  96. Function DoExtractParam (Params As String, sRtn As String)
  97.  Dim pStart, pEnd As Integer
  98.  Dim rtn As Integer
  99.    DoExtractParam = True
  100.    ' Extract next parameter
  101.    If Len(Params) = 0 Then
  102.       DoExtractParam = False
  103.       Exit Function
  104.    End If
  105.    ' First, extract the next parameter and update the
  106.    ' Params string.
  107.    rtn = InStr(1, Params, ",") ' look next for commas
  108.    If rtn > 0 Then
  109.       ' More parameters follow. Extract the first into
  110.       ' 'sRtn' and update the Params string
  111.       sRtn = LTrim$(RTrim$(Left$(Params, rtn - 1)))
  112.       Params = Right$(Params, Len(Params) - rtn - 1)
  113.    Else
  114.       ' No parameters follow.
  115.       sRtn = LTrim$(RTrim$(Params))
  116.       Params = ""
  117.    End If
  118.    ' Clean up sRtn. Eliminate any leading or trailing
  119.    ' parenthesis and blanks
  120.    If Left$(sRtn, 1) = Chr$(34) Then
  121.       sRtn = LTrim$(Right$(sRtn, Len(sRtn) - 1))
  122.    End If
  123.    If Right$(sRtn, 1) = Chr$(34) Then
  124.       sRtn = RTrim$(Left$(sRtn, Len(sRtn) - 1))
  125.    End If
  126. End Function
  127. Function DoLinkExecute (CmdStr As String)
  128.  Dim CommandStr As String
  129.  Dim CmdNumber As Integer
  130.  Dim Params As String
  131.  Dim rtn As Integer
  132.    ' Provide for simple execution commands.
  133.    ' Return TRUE if successful, FALSE otherwise.
  134.    ' Make local copy of command string
  135.    CommandStr = CmdStr
  136.    rtn = ParseCommand(CommandStr, CmdNumber, Params)
  137.    Do While rtn <> -1
  138.       Select Case CmdNumber
  139.       Case EC_DISPLAYABOUT
  140.          MsgBox "Display About..." + Params
  141.       Case EC_SHELLAPP
  142.          If Cmd_ShellApp(Params) = 0 Then GoTo ExecuteError
  143.       Case Else
  144.       End Select
  145.       If rtn = 0 Then
  146.          DoLinkExecute = False
  147.          Exit Function
  148.       End If
  149.       rtn = ParseCommand(CommandStr, CmdNumber, Params)
  150.    Loop
  151. ExecuteError:
  152.    ' Error has occurred. Return TRUE.
  153.    DoLinkExecute = True
  154. End Function
  155. Sub Form_LinkClose ()
  156.    DisplayStatus "Link Closed"
  157. End Sub
  158. Sub Form_LinkError (LinkErr As Integer)
  159.    DisplayStatus "Link Error : " + Str$(LinkErr)
  160. End Sub
  161. Sub Form_LinkExecute (CmdStr As String, Cancel As Integer)
  162.    DisplayStatus "Link Execute Attempted"
  163.    Cancel = DoLinkExecute(CmdStr)
  164. End Sub
  165. Sub Form_LinkOpen (Cancel As Integer)
  166.    DisplayStatus "Link Opened"
  167. End Sub
  168. Sub Form_Load ()
  169.    LoadExecuteCmds
  170. End Sub
  171. Sub Form_Resize ()
  172.    lblStatus.Move 0, ScaleHeight - 255, ScaleWidth, 255
  173. End Sub
  174. Sub LoadExecuteCmds ()
  175.    ' Load Execution commands into array. To add new
  176.    ' commands, be certain to update the NUMEXECUTECMDS
  177.    ' constant in the forms general declarations section.
  178.    ExecuteCmd(EC_DISPLAYABOUT) = "DisplayAbout"
  179.    ExecuteCmd(EC_SHELLAPP) = "ShellApp"
  180. End Sub
  181. Sub mnuOption_Click (Index As Integer)
  182.    Select Case Index
  183.    Case IDM_TOPMOST
  184.       If mnuOption(Index).Checked Then
  185.          SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
  186.       Else
  187.          SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
  188.       End If
  189.    End Select
  190.    ' Toggle menu checkmark
  191.    mnuOption(Index).Checked = Not mnuOption(Index).Checked
  192. End Sub
  193. Function ParseCommand (CmdStr As String, CmdNumber As Integer, Params As String)
  194.  Dim CmdStart, CmdEnd, NextCmd As Integer
  195.  Dim pStart, pEnd As Integer
  196.  Dim Cmd As String
  197.  Dim ii As Integer
  198.    ' Parse LinkExecute command and return the command number
  199.    ' and the parameter string. Return 1 if a valid command
  200.    ' is found, -1 if an invalid command is found, else
  201.    ' return 0 if end of command string.
  202.    ' Find first left square bracket. If CmdStart = 1, no bracket
  203.    ' was found and we can assume no more commands exist so
  204.    ' we return a 0.
  205.    CmdStart = InStr(CmdStr, "[") + 1
  206.    If CmdStart = 1 Then ParseCommand = 0: Exit Function
  207.    ' If CmdEnd is -1, no following left parenthesis was found.
  208.    ' Hence, an error was found.
  209.    CmdEnd = InStr(CmdStart, CmdStr, "(") - 1
  210.    If CmdEnd = -1 Then ParseCommand = -1: Exit Function
  211.    Cmd = UCase$(LTrim$(RTrim$(Mid$(CmdStr, CmdStart, CmdEnd - CmdStart + 1))))
  212.    pStart = InStr(CmdStart, CmdStr, "(") + 1
  213.    pEnd = InStr(pStart, CmdStr, ")") - 1
  214.    NextCmd = InStr(pEnd, CmdStr, "[")
  215.    ' Find Cmd in ExecuteCmd array
  216.    For ii = 0 To NUMEXECUTECMDS
  217.       If UCase$(ExecuteCmd(ii)) = Cmd Then
  218.          ' Return the command number and parameters
  219.          Params = Mid$(CmdStr, pStart, pEnd - pStart + 1)
  220.          CmdNumber = ii
  221.          If NextCmd = 0 Then
  222.             ' No following command; return 0
  223.             ParseCommand = 0
  224.          Else
  225.             ' Additional commands follow. Remove this
  226.             ' command from CmdStr and return 1.
  227.             CmdStr = Right$(CmdStr, Len(CmdStr) - NextCmd + 1)
  228.             ' Set the return value
  229.             ParseCommand = 1
  230.          End If
  231.          Exit Function
  232.       End If
  233.    Next ii
  234.    ParseCommand = -1
  235. End Function
  236. Sub Text1_Change ()
  237.    DisplayStatus ""
  238. End Sub
  239. Sub Text2_Change ()
  240.    DisplayStatus ""
  241. End Sub
  242.